import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
   void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}
public class Test {

    public static void main(String[] args) {
        Map<String,Integer> hashMap = new HashMap<>();
        hashMap.put("hello",3);
        hashMap.put("eee",4);
        hashMap.put("htttello",6);
       /* hashMap.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println("key:" + s + "val :" + integer);
            }
        });*/
        hashMap.forEach((String s,Integer integer) -> {
            System.out.println("key:" + s + "val :" + integer);
        });


    }
    public static void main5(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("hello");
        list.add("123");
        list.add("zzz");

//        list.forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });
        list.forEach(s -> System.out.println(s));
        System.out.println("==================");

        /*list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);

            }
        });*/
        list.sort((o1,o2) -> {
            return o1.compareTo(o2);
        });
        list.forEach(s -> System.out.println(s));


    }
    public static void main4(String[] args) {
        //变量捕获  ->变量一定是常量或者从来没被修改过
        int a = 10;
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {

                System.out.println("hello->" + a);
            }
        };
        noParameterNoReturn.test();

        NoParameterNoReturn noParameterNoReturn2 = () -> {
            System.out.println("hello" + a);
        };
        noParameterNoReturn.test();
    }
    //有返回值 , 没有参数
    public static void main3(String[] args) {
        //可以省略return
        NoParameterReturn noParameterReturn = () -> {
            return 10;
        };
        int ret = noParameterReturn.test();
        System.out.println(ret);

        OneParameterReturn oneParameterReturn = (int x) -> {
          return x+10;
        };
        ret = oneParameterReturn.test(9);
        System.out.println(ret);

        MoreParameterReturn moreParameterReturn = (int x , int y) -> {
          return x*y;
        };
        ret = moreParameterReturn.test(10,20);
        System.out.println(ret);


    }
    //没有返回值 , 有参数
    public static void main2(String[] args) {
        NoParameterNoReturn noParameterNoReturn = () -> {
            System.out.println("hello");
        };
        noParameterNoReturn.test();

        //参数的类型 只有一个的时候 , 可以省略 , 还可以省略参数的括号
        OneParameterNoReturn oneParameterNoReturn = (int x) -> {
            System.out.println(x+10);
        };
        oneParameterNoReturn.test(29);

        //类型不可以单独省略 , 除非一起省略
        MoreParameterNoReturn moreParameterNoReturn = (int x,int y) -> {
            System.out.println(x + y);
        };
        moreParameterNoReturn.test(2,5);



    }
    public static void main1(String[] args) {
        //一个类实现了这个接口 , 并且重写了这个方法!! 匿名内部类
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("hello");
            }
        };
        noParameterNoReturn.test();
    }
}
